/*     */ package com.zimbra.cs.account.accesscontrol;
/*     */ 
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.AlwaysOnCluster;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.DynamicGroup;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.GroupMembership;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.UCService;
/*     */ import com.zimbra.cs.account.XMPPComponent;
/*     */ import com.zimbra.cs.account.Zimlet;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PseudoTarget
/*     */ {
/*     */   static class PseudoZimbraId
/*     */   {
/*     */     private static final String PSEUDO_ZIMBRA_ID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
/*     */     
/*     */     static String getPseudoZimbraId()
/*     */     {
/*  50 */       return "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
/*     */     }
/*     */     
/*     */     static boolean isPseudoZimrbaId(String zid) {
/*  54 */       return "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa".equals(zid);
/*     */     }
/*     */   }
/*     */   
/*     */   public static boolean isPseudoEntry(Entry entry) {
/*  59 */     if (((entry instanceof PseudoAccount)) || ((entry instanceof PseudoCalendarResource)) || ((entry instanceof PseudoDistributionList)) || ((entry instanceof PseudoCos)) || ((entry instanceof PseudoDomain)) || ((entry instanceof PseudoServer)) || ((entry instanceof PseudoUCService)) || ((entry instanceof PseudoXMPPComponent)) || ((entry instanceof PseudoZimlet)))
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  68 */       return true;
/*     */     }
/*  70 */     return false;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   static class PseudoAccount
/*     */     extends Account
/*     */   {
/*     */     Domain mPseudoDomain;
/*     */     
/*     */ 
/*     */ 
/*     */     Provisioning.GroupMembership mAclGroups;
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */     PseudoAccount(String name, String id, Map<String, Object> attrs, Map<String, Object> defaults, Provisioning prov, Domain pseudoDomain)
/*     */     {
/*  91 */       super(id, attrs, defaults, prov);
/*  92 */       this.mPseudoDomain = pseudoDomain;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     PseudoAccount(String name, String id, Map<String, Object> attrs, Map<String, Object> defaults, Provisioning prov, DistributionList group)
/*     */       throws ServiceException
/*     */     {
/* 103 */       super(id, attrs, defaults, prov);
/* 104 */       this.mAclGroups = prov.getGroupMembership(group, false);
/*     */     }
/*     */     
/*     */     Domain getPseudoDomain() {
/* 108 */       return this.mPseudoDomain;
/*     */     }
/*     */     
/*     */     Provisioning.GroupMembership getAclGroups() {
/* 112 */       return this.mAclGroups;
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoCalendarResource extends CalendarResource
/*     */   {
/*     */     Domain mPseudoDomain;
/*     */     
/*     */     public PseudoCalendarResource(String name, String id, Map<String, Object> attrs, Map<String, Object> defaults, Provisioning prov, Domain pseudoDomain) {
/* 121 */       super(id, attrs, defaults, prov);
/* 122 */       this.mPseudoDomain = pseudoDomain;
/*     */     }
/*     */     
/*     */     Domain getPseudoDomain() {
/* 126 */       return this.mPseudoDomain;
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoDistributionList extends DistributionList
/*     */   {
/*     */     Domain mPseudoDomain;
/*     */     
/*     */     public PseudoDistributionList(String name, String id, Map<String, Object> attrs, Provisioning prov, Domain pseudoDomain) {
/* 135 */       super(id, attrs, prov);
/* 136 */       this.mPseudoDomain = pseudoDomain;
/*     */     }
/*     */     
/*     */     Domain getPseudoDomain() {
/* 140 */       return this.mPseudoDomain;
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoDynamicGroup extends DynamicGroup
/*     */   {
/*     */     Domain mPseudoDomain;
/*     */     
/*     */     public PseudoDynamicGroup(String name, String id, Map<String, Object> attrs, Provisioning prov, Domain pseudoDomain) {
/* 149 */       super(id, attrs, prov);
/* 150 */       this.mPseudoDomain = pseudoDomain;
/*     */     }
/*     */     
/*     */     Domain getPseudoDomain() {
/* 154 */       return this.mPseudoDomain;
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoCos extends Cos {
/*     */     private PseudoCos(String name, String id, Map<String, Object> attrs, Provisioning prov) {
/* 160 */       super(id, attrs, prov);
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoDomain extends Domain
/*     */   {
/*     */     private PseudoDomain(String name, String id, Map<String, Object> attrs, Map<String, Object> defaults, Provisioning prov) {
/* 167 */       super(id, attrs, defaults, prov);
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoServer extends Server
/*     */   {
/*     */     private PseudoServer(String name, String id, Map<String, Object> attrs, Map<String, Object> defaults, Provisioning prov) {
/* 174 */       super(id, attrs, defaults, prov);
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoAlwaysOnCluster extends AlwaysOnCluster
/*     */   {
/*     */     private PseudoAlwaysOnCluster(String name, String id, Map<String, Object> attrs, Map<String, Object> defaults, Provisioning prov) {
/* 181 */       super(id, attrs, defaults, prov);
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoUCService extends UCService
/*     */   {
/*     */     private PseudoUCService(String name, String id, Map<String, Object> attrs, Provisioning prov) {
/* 188 */       super(id, attrs, prov);
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoXMPPComponent extends XMPPComponent {
/*     */     private PseudoXMPPComponent(String name, String id, Map<String, Object> attrs, Provisioning prov) {
/* 194 */       super(id, attrs, prov);
/*     */     }
/*     */   }
/*     */   
/*     */   static class PseudoZimlet extends Zimlet {
/*     */     private PseudoZimlet(String name, String id, Map<String, Object> attrs, Provisioning prov) {
/* 200 */       super(id, attrs, prov);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static Domain createPseudoDomain(Provisioning prov)
/*     */     throws ServiceException
/*     */   {
/* 211 */     return (Domain)createPseudoTarget(prov, TargetType.domain, null, null, false, null, null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static Domain createPseudoDomain(Provisioning prov, String domainName)
/*     */     throws ServiceException
/*     */   {
/* 227 */     return (Domain)createPseudoTarget(prov, TargetType.domain, null, null, false, null, null, domainName);
/*     */   }
/*     */   
/*     */ 
/*     */   public static Entry createPseudoTarget(Provisioning prov, TargetType targetType, Key.DomainBy domainBy, String domainStr, boolean createPseudoDomain, Key.CosBy cosBy, String cosStr)
/*     */     throws ServiceException
/*     */   {
/* 234 */     return createPseudoTarget(prov, targetType, domainBy, domainStr, createPseudoDomain, cosBy, cosStr, null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static Entry createPseudoTarget(Provisioning prov, TargetType targetType, Key.DomainBy domainBy, String domainStr, boolean createPseudoDomain, Key.CosBy cosBy, String cosStr, String domainName)
/*     */     throws ServiceException
/*     */   {
/* 271 */     Entry targetEntry = null;
/* 272 */     Config config = prov.getConfig();
/*     */     
/* 274 */     String zimbraId = PseudoZimbraId.getPseudoZimbraId();
/* 275 */     Map<String, Object> attrMap = new HashMap();
/* 276 */     attrMap.put("zimbraId", zimbraId);
/*     */     
/* 278 */     Domain pseudoDomain = null;
/* 279 */     Domain domain = null;
/* 280 */     if ((targetType == TargetType.account) || (targetType == TargetType.calresource) || (targetType == TargetType.dl) || (targetType == TargetType.group))
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/* 285 */       if (createPseudoDomain) {
/* 286 */         domain = pseudoDomain = (Domain)createPseudoTarget(prov, TargetType.domain, null, null, false, null, null);
/*     */       }
/*     */       else {
/* 289 */         if ((domainBy == null) || (domainStr == null))
/* 290 */           throw ServiceException.INVALID_REQUEST("domainBy and domain identifier is required", null);
/* 291 */         domain = prov.get(domainBy, domainStr);
/*     */       }
/* 293 */       if (domain == null) {
/* 294 */         throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
/*     */       }
/*     */     }
/*     */     
/* 298 */     switch (targetType) {
/*     */     case account: 
/*     */     case calresource: 
/* 301 */       Cos cos = null;
/* 302 */       if ((cosBy != null) && (cosStr != null)) {
/* 303 */         cos = prov.get(cosBy, cosStr);
/* 304 */         if (cos == null) {
/* 305 */           throw AccountServiceException.NO_SUCH_COS(cosStr);
/*     */         }
/* 307 */         attrMap.put("zimbraCOSId", cos.getId());
/*     */       } else {
/* 309 */         String domainCosId = domain != null ? domain.getAttr("zimbraDomainDefaultCOSId", null) : null;
/*     */         
/* 311 */         if (domainCosId != null) {
/* 312 */           cos = prov.get(Key.CosBy.id, domainCosId);
/*     */         }
/* 314 */         if (cos == null) {
/* 315 */           cos = prov.get(Key.CosBy.name, "default");
/*     */         }
/*     */       }
/*     */       
/* 319 */       if (targetType == TargetType.account) {
/* 320 */         targetEntry = new PseudoAccount("pseudo@" + domain.getName(), zimbraId, attrMap, cos.getAccountDefaults(), prov, pseudoDomain);
/*     */ 
/*     */ 
/*     */       }
/*     */       else
/*     */       {
/*     */ 
/* 327 */         targetEntry = new PseudoCalendarResource("pseudo@" + domain.getName(), zimbraId, attrMap, cos.getAccountDefaults(), prov, pseudoDomain);
/*     */       }
/*     */       
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 334 */       break;
/*     */     
/*     */     case cos: 
/* 337 */       targetEntry = new PseudoCos("pseudocos", zimbraId, attrMap, prov, null);
/* 338 */       break;
/*     */     case dl: 
/* 340 */       targetEntry = new PseudoDistributionList("pseudo@" + domain.getName(), zimbraId, attrMap, prov, pseudoDomain);
/* 341 */       break;
/*     */     case group: 
/* 343 */       targetEntry = new PseudoDynamicGroup("pseudo@" + domain.getName(), zimbraId, attrMap, prov, pseudoDomain);
/* 344 */       break;
/*     */     case domain: 
/* 346 */       String name = domainName == null ? "pseudo.pseudo" : domainName;
/* 347 */       targetEntry = new PseudoDomain(name, zimbraId, attrMap, config.getDomainDefaults(), prov, null);
/* 348 */       break;
/*     */     case server: 
/* 350 */       targetEntry = new PseudoServer("pseudo.pseudo", zimbraId, attrMap, config.getServerDefaults(), prov, null);
/* 351 */       break;
/*     */     case alwaysoncluster: 
/* 353 */       targetEntry = new PseudoAlwaysOnCluster("pseudo.pseudo", zimbraId, attrMap, null, prov, null);
/* 354 */       break;
/*     */     case ucservice: 
/* 356 */       targetEntry = new PseudoUCService("pseudo", zimbraId, attrMap, prov, null);
/* 357 */       break;
/*     */     case xmppcomponent: 
/* 359 */       targetEntry = new PseudoXMPPComponent("pseudo", zimbraId, attrMap, prov, null);
/* 360 */       break;
/*     */     case zimlet: 
/* 362 */       targetEntry = new PseudoZimlet("pseudo", zimbraId, attrMap, prov, null);
/* 363 */       break;
/*     */     default: 
/* 365 */       throw ServiceException.INVALID_REQUEST("unsupported target for createPseudoTarget: " + targetType.getCode(), null);
/*     */     }
/*     */     
/* 368 */     return targetEntry;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/accesscontrol/PseudoTarget.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */